package com.justnow;

public class Solution09 {

    public static void main(String[] args) {
        Solution09 solution09 = new Solution09();
        String num1 = "1234567";
        String num2 = "227";
        String add = solution09.add(num1, num2);
        System.out.println(add);
    }
    public String add(String num1, String num2) {
        StringBuilder str1 = new StringBuilder(num1).reverse();
        StringBuilder str2 = new StringBuilder(num2).reverse();
        StringBuilder res = new StringBuilder();
        int i = num1.length() - 1, j = num2.length() - 1, carry = 0;
        while(i >= 0 || j >= 0){
            int n1 = i >= 0 ? num1.charAt(i) - '0' : 0;
            int n2 = j >= 0 ? num2.charAt(j) - '0' : 0;
            int tmp = n1 + n2 + carry;
            carry = tmp / 10;
            res.append(tmp % 10);
            i--; j--;
        }
        if(carry == 1) res.append(1);
        return res.reverse().toString();
    }
}
